package com.st.swagger.controller;

import com.st.swagger.entity.Carousel;
import com.st.swagger.service.CarouselService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/carousels")
@Api(tags = "0414姚炜煊轮播图管理接口")
public class CarouselController {

    @Autowired
    private CarouselService carouselService;

    @ApiOperation("获取所有轮播图")
    @GetMapping
    public ResponseEntity<List<Carousel>> getAllCarousels() {
        return ResponseEntity.ok(carouselService.getAllCarousels());
    }

    @ApiOperation("根据ID获取轮播图")
    @GetMapping("/{id}")
    public ResponseEntity<Carousel> getCarouselById(@PathVariable Long id) {
        return ResponseEntity.ok(carouselService.getCarouselById(id));
    }

    @ApiOperation("创建轮播图")
    @PostMapping
    public ResponseEntity<String> createCarousel(@RequestBody Carousel carousel) {
        carouselService.createCarousel(carousel);
        return ResponseEntity.ok("轮播图创建成功");
    }

    @ApiOperation("更新轮播图")
    @PutMapping("/{id}")
    public ResponseEntity<String> updateCarousel(@PathVariable Long id, @RequestBody Carousel carousel) {
        carouselService.updateCarousel(id, carousel);
        return ResponseEntity.ok("轮播图更新成功");
    }

    @ApiOperation("删除轮播图")
    @DeleteMapping("/{id}")
    public ResponseEntity<String> deleteCarousel(@PathVariable Long id) {
        carouselService.deleteCarousel(id);
        return ResponseEntity.ok("轮播图删除成功");
    }
}

